package android.maps;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class Home extends Activity {
    /** Called when the activity is first created. */
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ParserCabanas parser = new ParserCabanas();
        parser.getCabanas(20);
    }
    ////////////////////////////////No pescar//////////////////////////////////////
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	// TODO Auto-generated method stub
    	MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_home, menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.MnuOpc1:
            	Intent cambio = new Intent(Home.this, CrearViaje.class);
            	startActivity(cambio);
            	onPause();
                return true;
            case R.id.MnuOpc2:
            	showDialog();
            	return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
    void showDialog(){
    	AlertDialog.Builder alert = new AlertDialog.Builder(this);
 	   	alert.setTitle("Advertencia");
    	alert.setMessage("¿Desea realmente salir de la aplicación?");
 	    alert.setCancelable(false);
 	    alert.setPositiveButton("Sí", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int id) {
                  salir();
              }
         	 });
 	      alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
 	              public void onClick(DialogInterface dialog, int id) {
 	                   dialog.cancel();
 	              }
 	          });
 	   AlertDialog mensaje = alert.create();
 	   mensaje.show();
    }
    public void salir(){
        setResult(RESULT_OK);
        finish();
    }
}